<script setup>
import { ref, watch } from 'vue';

const totalCount = ref(100)
const msg = ref('Hello')

// 侦听一个响应式数据
watch(totalCount, (newValue, oldValue) => {
  console.log('totalCount', { newValue, oldValue })
})

// 支持同时侦听多个值(了解)
watch([totalCount, msg], (newValue, oldValue) => {
  console.log('[totalCount,msg]', { newValue, oldValue })
})
</script>

<template>
  <!-- 结构 -->
  <h1>{{ totalCount }}</h1>
  <button @click="totalCount++">点击累加</button>
  <button @click="msg += '~'">{{ msg }}</button>
</template>

<style scoped>
/* 样式 */
</style>
